// pages/teacher/teacher.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    choose:0,
    style:[],
    size: 0,
    total: 0,
    array:[]
  },
  stop: 1,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.request({
      url: 'https://www.citycreate.cn/bbj/wx/major/list.html',
      success: (res) => {
        this.setData({
          style: res.data.data
        }, () => {
          this.data.style.map((item, index) => {
            if (index == 0) {
              this.setData({
                choose: item.id
              })
              this.loading(1);
            }
          })
        })
      }
    })
  },
  loading(item) {
    if (this.stop == 0) {
      wx.showToast({
        title: '请慢点操作',
        icon: 'success',
        duration: 2000
      })
      return false
    }
    wx.request({
      url: 'https://www.citycreate.cn/bbj/wx/teacher/list.html',
      data: {
        pageNo: 1,
        pageSize: 4,
        categoryId: this.data.choose
      },
      success: (res) => {
        this.setData({
          array: res.data.data.list,
          size: res.data.data.pageNo,
          total: res.data.data.totalPage
        }, () => {
          console.log(this.data.array)
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.total > this.data.size && this.stop == 1) {
      var that = this
      this.stop = 0;
      wx.request({
        url: 'https://www.citycreate.cn/bbj/wx/teacher/list.html',
        data: {
          pageNo: that.data.size + 1,
          pageSize: 4,
          categoryId: this.data.choose
        },
        success: function (res) {
          that.setData({
            array: that.data.array.concat(res.data.data.list),
            size: res.data.data.pageNo,
            total: res.data.data.totalPage
          }, () => {
            that.stop = 1
          })
        }
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
   chooseActive(item){
     this.setData({
       choose: item.currentTarget.id
     }, () => {
       this.loading(1);
     })
  },
  to(item){
    wx.navigateTo({
      url: '../teacherDetail/about?id=' + item.currentTarget.id,
    })
  }
})